<template>
  <div>
    <Header />
    <Search :cities="cities" />
    <List :cities="cities" :hot="hotCities" :letter="letter" />
    <Alphabet :cities="cities" @change="handleLetterChange" />
  </div>
</template>

<script>
import axios from "axios";
import Header from "./component/Header";
import Search from "./component/Search";
import List from "./component/List";
import Alphabet from "./component/Alphabet";

export default {
  name: "City",
  components: {
    Header,
    Search,
    List,
    Alphabet,
  },

  data() {
    return {
      cities: {},
      hotCities: [],
      letter: "",
    };
  },

  methods: {
    getCityInfo() {
      axios.get("/mock/city").then(this.handleGetCityInfoSucc).catch(e => console.log(e))

      // axios.get("/static/mock/city.json").then(this.handleGetCityInfoSucc);
    },
    handleGetCityInfoSucc(res) {
      res = res.data.data;
      if (res.ret && res.data) {
        const data = res.data;
        this.cities = data.cities;
        this.hotCities = data.hotCities;
      }
    },
    handleLetterChange(letter) {
      this.letter = letter;
      // debugger
      // console.log(letter);
    },
  },
  mounted() {
    this.getCityInfo();
  },
};
</script>

<style lang="stylus" scoped></style>